
#include "wtp_state.h"

int WaitDTLS = 0; 	/* 4.7 */

/* 
	API notifications
*/
int DTLSPeerAuthorize;
int DTLSEstablished;
int DTLSEstablishFail;
int DTLSAuthenticateFail;
int DTLSAborted;
int DTLSReassemblyFailure;
int DTLSDecapFailure;
int DTLSPeerDisconnect;

/* 	2.3.2.1 
	Six commands are defined for the CAPWAP to DTLS API.
*/
int DTLSStart()
{

}

int DTLSListen()
{

}

int DTLSAccept()
{

}

int DTLSAbortSession()
{

}

int DTLSShutdown()
{

}

int DTLSMtuUpdate()
{

}


wtp_state_t wtp_state_dtls_setup()
{
	DTLSStart();
	
	if(DTLSEstablishFail) {
		FailedDTLSSessionCount++;
		FailedDTLSAuthFailCount++;
	}
	
	if(FailedDTLSSessionCount >= MaxFailedDTLSSessionRetry) {
		return WTP_STATE_SULKING;
	}
	
	if(DTLSPeerAuthorize) {
		return WTP_STATE_AUTHORIZE;
	}
}

wtp_state_t wtp_state_authorize()
{
	if(!authorize) {
		DTLSAbortSession;
		DTLSSessionDelete();
	}
		
	return WTP_STATE_DTLS_CONNECT;
}
wtp_state_t wtp_state_dtls_connect()
{
	if(DTLSAborted)
		FailedDTLSSessionCount++;
	
	if(DTLSAuthenticateFail)
		FailedDTLSAuthFailCount++;
	
	if(DTLSAborted || DTLSAuthenticateFail)
		DTLSSessionDelete;
	
	if(DTLSEstablished) {
		FailedDTLSSessionCount = 0;
		WaitDTLS = 0;
	}
	
	return WTP_STATE_JOIN;
}

wtp_state_t wtp_state_dtls_td()
{
	return WTP_STATE_IDLE;
}
wtp_state_t wtp_state_join()
{
	if(!(Join Response)) {
		DTLSShutdown
	}
	
	if(DTLSAborted || DTLSReassemblyFailure || DTLSPeerDisconnect) {
		DTLSSessionDelete;
	}
	
	if(Image Identifier message != software version) 
		return WTP_STATE_IMAGE_DATA;
	
	return WTP_STATE_CONFIGURE;
}